from pygame.constants import MOUSEBUTTONDOWN
from lib.ZButton import ZButton
from lib.res.fun import _create_sound
from lib.res.glo import SRC


class MenuBtn ( ZButton ) :
    def __init__ ( self , father , default , over ) :
        super ( MenuBtn , self ).__init__ ( father , default , over )
        self.defaultsound = SRC [ 'sound' ] [ 'default' ]
        self.onclicksound = _create_sound ( SRC [ 'sound' ] [ 'ok' ] )
        self.onmouseoversound = _create_sound ( self.defaultsound )

    def update ( self , event , mouse_pos , mouse_key ) :
        super ( MenuBtn , self ).update ( event , mouse_pos , mouse_key )
        if self._running :
            if self.isover ( mouse_pos , mouse_key ) :
                if self.onmouseoversound.get_num_channels ( ) < 1 :
                    self.onmouseoversound.play ( )
            else :
                self.onmouseoversound = None
                self.onmouseoversound = _create_sound ( self.defaultsound )

    def isclick ( self , mouse_pos , mouse_key ) :
        super ( MenuBtn , self ).isclick ( mouse_pos , mouse_key )
        if self.isover ( mouse_pos , mouse_key ) :
            self.onclicksound.play ( )
